<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function (){
            // 1 1 2 3 5 8 13
            // 定义函数
            function fun (n){
                return n>2?fun(n-1)+fun(n-2):1;
            }
            // 为按钮绑定单击响应函数
            document.getElementById("btn").onclick = function(){
                // 获取输入框中的值
                var number = document.getElementById("ipt").value;
                // 输出斐波那切数列的第number项
                alert(fun(number));
            }
        }
    </script>
</head>
<body>
    <input type="text" id="ipt" placeholder="数值"> <button id="btn">计算</button>
</body>
</html>